<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org" xmlns:v-on="http://www.w3.org/1999/xhtml"
      xmlns:v-if="http://www.w3.org/1999/xhtml">
<head th:replace="~{baseui/head :: head}">
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="description" content="动检通智慧云平台"/>
    <meta name="author" content="牧中(上海)物联网科技有限公司"/>
    <link rel="shortcut icon" href="/webjars/images/favicon.png"/>

    <title>牧中畜牧业大数据智慧云平台V1.0</title>


</head>
<body>
<!--顶部一级导航-->
<th:block th:replace="baseui/topheader :: topheader(1)"/>

<!--动检通菜单-->
<div id="topnav" th:replace="djt/partial/topnav :: topnav(5)"></div>


<div id="cl-wrapper">
    <!--左边导航-->
    <th:block th:replace="djt/partial/harmless_left :: nav(2)"/>

    <div class="container-fluid" id="pcont">
        <div class="cl-mcont">
            <div class="row">
                <div class="col-md-12">
                    <div class="block-flat">
                        <div id="show" class="header from-group"><h3>无害化记录</h3>
                        </div>

                        <div class="content">
                            <div class="table-responsive">
                                <div id="datatable_wrapper"
                                     class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                                    <div class="row">

                                        <div class="from-group">
                                            <div id="but" class="btn-group col-sm-2" style="width: 180px;float: left">
                                                <input type="hidden" id="hiddate" value="1"/>
                                                <button date-id="but1" type="button"
                                                        class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(1)">
                                                    日
                                                </button>
                                                <button date-id="but2" type="button" class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(2)">
                                                    周
                                                </button>
                                                <button date-id="but3" type="button" class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(3)">
                                                    月
                                                </button>
                                                <button date-id="but4" type="button" class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(4)">
                                                    季
                                                </button>
                                                <button date-id="but6" type="button" class="btn btn-default btn-sm"
                                                        onclick="SimpleSearch(6)">
                                                    年
                                                </button>
                                            </div>

                                            <div class="col-sm-2">
                                                <div class="input-group date datetime col-md-5 col-xs-7"
                                                     data-min-view="2" data-date-format="yyyy-mm-dd">
                                                    <input id="start" class="form-control" style="width: 90px;"
                                                           size="16"
                                                           type="text" value="" placeholder="开始时间" readonly>
                                                    <span class="input-group-addon btn btn-primary"><span
                                                            class="glyphicon glyphicon-th"></span></span>
                                                </div>
                                            </div>
                                            <div class="col-sm-2">
                                                <div class="input-group date datetime col-md-5 col-xs-7"
                                                     data-min-view="2" data-date-format="yyyy-mm-dd">
                                                    <input id="end" class="form-control" style="width: 90px;" size="16"
                                                           type="text" value="" placeholder="结束时间" readonly>
                                                    <span class="input-group-addon btn btn-primary"><span
                                                            class="glyphicon glyphicon-th"></span></span>
                                                </div>


                                            </div>

                                            <!--<option value="">养殖场名称</option>
                                            <option th:each=" breedfactory : ${factoryname}" th:text="${breedfactory.name}"
                                                    th:value="${breedfactory.name}"></option>-->
                                            <div class="col-sm-2">
                                                <select id="area" class="select2">
                                                    <option value="">所有区域</option>
                                                    <optgroup th:each="cityarea:${areaList}"
                                                              th:label="${cityarea.city}">
                                                        <option th:each="regions:${cityarea.regions}"
                                                                th:text="${regions}" th:value="${regions}"></option>
                                                    </optgroup>

                                                </select>

                                            </div>
                                            <div class="col-sm-2">
                                                <select id="type" class="select2">
                                                    <option value="0">动物种类</option>
                                                    <option value="1">猪</option>
                                                    <option value="2">牛</option>
                                                    <option value="3">羊</option>
                                                    <option value="4">家禽</option>

                                                </select>

                                            </div>


                                        </div>
                                    </div>
                                    <div class="row" style="margin-left: 173px">
                                        <div class="from-group">

                                            <div class="col-sm-2" style="width: 150px">
                                                <!-- 0: '请选择',
                                                     1: '集中处理',
                                                     2: '焚烧',
                                                     3: '化制',
                                                     4: '掩埋',
                                                     5: '发酵',
                                                     6: '其它',-->
                                                <select id="method" class="select2">
                                                    <option value="0">处理方式</option>
                                                    <option value="1">集中处理</option>
                                                    <option value="2">焚烧</option>
                                                    <option value="3">化制</option>
                                                    <option value="4">掩埋</option>
                                                    <option value="5">发酵</option>
                                                    <option value="6">其它</option>
                                                </select>

                                            </div>
                                            <div class="col-sm-2" style="width: 150px">
                                                <select id="reporttype" class="select2">
                                                    <option value="0">无害化来源</option>
                                                    <option value="1">产地检疫</option>
                                                    <option value="2">入场监督检查</option>
                                                    <option value="5">屠宰检疫-宰前检查</option>
                                                    <option value="6">屠宰检疫-同步检疫</option>
                                                </select>

                                            </div>

                                            <div class="col-sm-2" style="width: 150px">
                                                <button class="btn btn-primary" onclick="SearchBtn()" style="width: 80px">搜索</button>
                                            </div>
                                        </div>
                                    </div>
                                    <br/>

                                    <div class="row">
                                        <div class="col-sm-12">

                                            <!-- Table -->
                                            <table id="jqGrid"></table>
                                            <div id="jqGridPager"></div>

                                        </div>
                                    </div>


                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>

<script type="text/javascript" src="/webjars/js/jquery.js"></script>
<script type="text/javascript" src="/webjars/js/jquery.gritter/js/jquery.gritter.js"></script>

<script type="text/javascript" src="/webjars/js/jquery.nanoscroller/jquery.nanoscroller.js"></script>
<script type="text/javascript" src="/webjars/js/behaviour/general.js"></script>
<script src="/webjars/js/jquery.ui/jquery-ui.js" type="text/javascript"></script>

<script type="text/javascript" src="/webjars/js/jquery.nestable/jquery.nestable.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.switch/bootstrap-switch.min.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="/webjars/js/jquery.select2/select2.min.js" type="text/javascript"></script>
<script src="/webjars/js/skycons/skycons.js" type="text/javascript"></script>
<script src="/webjars/js/bootstrap.slider/js/bootstrap-slider.js" type="text/javascript"></script>
<script type="text/javascript" src="/webjars/js/jquery.niftymodals/js/jquery.modalEffects.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.summernote/dist/summernote.min.js"></script>


<script type="text/javascript" src="/webjars/js/jquery.magnific-popup/dist/jquery.magnific-popup.min.js"></script>


<script src="/webjars/js/behaviour/voice-commands.js"></script>
<script src="/webjars/js/bootstrap/dist/js/bootstrap.min.js"></script>

<script type="text/ecmascript" src="/webjars/jqgrid/js/i18n/grid.locale-cn.js"></script>
<script type="text/ecmascript" src="/webjars/jqgrid/js/jquery.jqGrid.min.js"></script>
<script src="/webjars/js/laydate/laydate.js"></script>
<script src="//vuejs.org/js/vue.min.js"></script>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
<script src="/webjars/js/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
    $(document).ready(function () {

        App.init();

        //grid
        $("#jqGrid").jqGrid({
            url: '/djt/harmless/harmlessindex',
            mtype: "GET",
            styleUI: 'Bootstrap',
            datatype: "json",
            autowidth: true,
            colModel: [
                {label: '<span style="text-align: center">序号</span>', name: 'harmless.id', key: true, width: 50, align: 'center', formatter: showid},
                {label: '<span style="text-align: center">区域</span>', name: 'breedFactory.region', width: 75, align: 'center'},
                {label: '<span style="text-align: center">编号</span>', name: 'harmless.number', width: 75, align: 'center'},
                {label: '<span style="text-align: center">关联类型</span>', name: 'harmless.reportType', width: 75, align: 'center',formatter:showreportstatus},
                {label: '<span style="text-align: center">货主</span>', name: 'harmless.factoryOwnerName', width: 75, align: 'center'},
                {label: '<span style="text-align: center">动物种类</span>', name: 'harmless.animalType', width: 80, align: 'center', formatter: showtype},
                {label: '<span style="text-align: center">数量及单位</span>', name: 'harmless.quantity', width: 100, align: 'center', formatter: shownum},
                {label: '<span style="text-align: center">处理方式</span>', name: 'harmless.treatment', width: 75, align: 'center', formatter: showmethod},
                {label: '<span style="text-align: center">养殖场</span>', name: 'harmless.breedFactoryName', width: 75, align: 'center'},
                {label: '<span style="text-align: center">屠宰场</span>', name: 'harmless.butcherFactoryName', width: 75, align: 'center'},
                {label: '<span style="text-align: center">检疫员</span>', name: 'harmless.quarantineUserName', width: 75, align: 'center'},
                {label: '<span style="text-align: center">状态</span>', name: 'harmless.status', width: 75, align: 'center', formatter: showstatus},
                {label: '<span style="text-align: center">日期</span>', name: 'harmless.createdAt', width: 100, align: 'center', formatter: ShowDate},
                {label: '<span style="text-align: center">详细</span>', width: 100, formatter: ShowOpertator, align: 'center'}
            ],
            viewrecords: true,
            align: 'center',
            height: 350,
            rowNum: 20,
            pager: "#jqGridPager"
        });

    });
    function ShowDate(cellvalue, options, rowObject) {
        if (cellvalue != null && cellvalue != "") {
            var timestamp4 = new Date(cellvalue);
            var dt = timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
            return dt;
        } else {
            return "";
        }
    }

    /* var start = {
     elem: '#start',
     format: 'YYYY/MM/DD hh:mm:ss',

     max: '2099-06-16 23:59:59', //最大日期
     istime: true,
     istoday: false,
     choose: function (datas) {
     end.min = datas; //开始日选好后，重置结束日的最小日期
     end.start = datas //将结束日的初始值设定为开始日
     }
     };
     var end = {
     elem: '#end',
     format: 'YYYY/MM/DD hh:mm:ss',
     max: '2099-06-16 23:59:59',
     istime: true,
     istoday: false,
     choose: function (datas) {
     start.max = datas; //结束日选好后，重置开始日的最大日期
     }
     };
     laydate(start);
     laydate(end);*/

    /*    function change(num) {
     $("#hiddate").val(num);
     $("button[date-id = but" + num + "]").addClass("active");
     $("button[date-id = but" + num + "]").siblings().removeClass("active");
     }*/

    function SearchBtn() {
        var time1 = $("#start").val();
        var time2 = $("#end").val();
        var area = $("#area").val();
        var type = $("#type").val();
        var method = $("#method").val();
        var reporttype = $("#reporttype").val();
        if (time1 == "") {
            time1 = new Date("2000-01-01 :00:00:00");
        } else {
            time1 = new Date(time1);
        }
        if (time2 == "") {
            time2 = new Date();
        } else {
            time2 = new Date(time2);
        }
        if (area == "") {
            area = null;
        }
        if (type == "") {
            type = 0;
        }
        if (method == "") {
            method = -5;
        }
        if(reporttype==""){
            reporttype==0;
        }
        var sdata = {   // 构建查询需要的参数
            start: time1,
            end: time2,
            area: area,
            type: type,
            method: method,
            reporttype: reporttype
        };

        var postData = $("#jqGrid").jqGrid("getGridParam", "postData");

        $.extend(postData, sdata);

        $("#jqGrid").jqGrid("setGridParam", {
            search: true    // (6)将jqGrid的search选项设为true
        }).trigger("reloadGrid", [{page: 1}]);   // (7)重新载入Grid表格，以使上述设置生效

    }

    var SimpleSearch = function (num) {
        var end = new Date();
        var start = new Date();
        switch (num) {
            case 1 :
                start = new Date(new Date() - 24 * 60 * 60 * 1000);
                break;
            case 2:
                start = new Date(new Date() - 7 * 24 * 60 * 60 * 1000);
                break;
            case 3:
                start = new Date(new Date() - 30 * 24 * 60 * 60 * 1000);
                break;
            case 4:
                start = new Date(new Date() - 4 * 30 * 24 * 60 * 60 * 1000);
                break;
            case 5:
                start = new Date(new Date() - 6 * 30 * 24 * 60 * 60 * 1000);
                break;
            case 6:
                start = new Date(new Date() - 12 * 30 * 24 * 60 * 60 * 1000);
                break;
        }
        var sdata = {   // 构建查询需要的参数
            start: start,
            end: end,
            area: $("#area").val(),
            type: $("#type").val(),
            method: $("#method").val(),
            reporttype: $("#reporttype").val()
        };

        var postData = $("#jqGrid").jqGrid("getGridParam", "postData");

        $.extend(postData, sdata);

        $("#jqGrid").jqGrid("setGridParam", {
            search: true    // (6)将jqGrid的search选项设为true
        }).trigger("reloadGrid", [{page: 1}]);   // (7)重新载入Grid表格，以使上述设置生效

    }

    function showid(cellvalue, options, rowObject) {
        return cellvalue == -1 ? "合计" : cellvalue;

    }
    function showtype(cellvalue, options, rowObject) {
        /*1、猪 2、牛 3、羊 4、家禽*/
        switch (cellvalue) {
            case 1:
                return "猪";
                break;
            case 2:
                return "牛";
                break;
            case 3:
                return "羊";
                break;
            case 4:
                return "家禽";
                break;
            default :
                return "";

        }
    }
    function showmethod(cellvalue, options, rowObject) {
        /*  0: '请选择',
         1: '集中处理',
         2: '焚烧',
         3: '化制',
         4: '掩埋',
         5: '发酵',
         6: '其它',*/
        switch (cellvalue) {
            case 1:
                return "集中处理";
                break;
            case 2:
                return "焚烧";
                break;
            case 3:
                return "化制";
                break;
            case 4:
                return "掩埋";
                break;
            case 5:
                return "发酵";
                break;
            case 6:
                return "其它";
                break;
            default :
                return "";

        }
    }

    function shownum(cellvalue, options, rowObject) {
        switch (rowObject.harmless.unit) {
            case 1:
                return cellvalue + "头";
                break;
            case 2:
                return cellvalue + "只";
                break;
            case 3:
                return cellvalue + "羽";
                break;
            case 4:
                return cellvalue + "克";
                break;
            case 5:
                return cellvalue + "毫升";
                break;
            case 6:
                return cellvalue + "头份";
                break;
            case 7:
                return cellvalue + "kg";
                break;
        }

    }
    function showreportstatus(cellvalue, options, rowObject) {
        /* 1 产地检疫 2 入场监督检查 5 屠宰检疫-宰前检查 6 屠宰检疫-同步检疫  */
        switch (cellvalue) {
            case 1:
                return "产地检疫";
                break;
            case 2:
                return "入场监督检查";
                break;
            case 5:
                return "屠宰检疫-宰前检查";
                break;
            case 6:
                return "屠宰检疫-同步检疫";
                break;
        }

    }
    /*0：未提交 1：待处理 2：完成*/
    function showstatus(cellvalue, options, rowObject) {
        switch (cellvalue) {
            case 1:
                return "待处理";
                break;
            case 2:
                return "完成";
                break;
            case 0:
                return "未提交";
                break;
        }

    }
    function showlocal(cellvalue, options, rowObject) {
        switch (cellvalue) {
            case 1:
                return "本地";
                break;
            case -1:
                return "外地";

        }

    }

    /* function ShowOpertator(cellvalue, options, rowObject) {
     var link;
     var rowval = rowObject["id"];
     link = "<button type='button' class='btn btn-default'>查看</button>"
     return rowObject.id == -1 ? "" : link;
     }*/

    function showimg(cellvalue, options, rowObject){
        var list = rowObject.photosJson;
    }

    function ShowOpertator(cellvalue, options, rowObject) {
        var link;
        var row = JSON.stringify(rowObject);
        link = "<button type='button' class='btn btn-default' id='" + row + "' onclick='select(this.id)'>查看</button>";
        return rowObject.id == -1 ? "" : link;
    }

    function select(data) {
        var json = JSON.parse(data);
        var type = showtype(json.harmless.animalType, null, null);
        var method = showmethod(json.harmless.treatment, null, null);
        var local = showlocal(json.harmless.isLocal, null, null);
        var timestamp4 = new Date(json.harmless.createdAt);
        var dt = timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
        var unit = shownum(json.harmless.quantity, null, json);
        layui.use(['laypage', 'layer'], function () {
            var $ = layui.jquery, layer = layui.layer;
            layer.open({
                type: 2,
                skin: 'layui-layer-lan',
                area: ['800px', '600px'],
                content: ['/djt/harmless/harmlessDetail', 'no'],
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    body.find("#factory").text(json.harmless.breedFactoryName);
                    body.find("#factorynum").text(json.breedFactory.id);
                    body.find("#region").text(json.breedFactory.region);
                    body.find("#stable").text(json.breedFactory.stableNumber);
                    body.find("#reportname").text(json.harmless.applyReportName);
                    body.find("#butchername").text(json.harmless.butcherFactoryName);
                    body.find("#protype").text(type);
                    body.find("#num").text(unit);
                    body.find("#treatment").text(method);
                    body.find("#quarantinename").text(json.harmless.quarantineUserName);
                    body.find("#islocal").text(local);
                    body.find("#createat").text(dt);



                    var tt=json.harmless.photosJsonMap;

                    for (var key in tt){
                        if (tt[key]!=null){
                            var a = "<img src="+tt[key]['uri']+" class='img-thumbnail' layer-src="+tt[key]['uri']+" style='width: 150px;height: 200px' onclick='showimg(this)'>";
                            if (tt[key]['uri']!=null&&tt[key]['uri']!=""){
                                body.find("#photosJson").append(a);
                            }
                        }


                    }

                }
            });

        });
    }

</script>


</body>
</html>
